﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>{{description}}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiAdmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiAdmin/style/admin.css" media="all">
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    {{ for item in searchfields }}
                    <div class="layui-inline">
                        <input type="text" name="{{item.field}}" placeholder="{{item.lablename}}" autocomplete="off" class="layui-input">
                    </div>{{ end }}
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-useradmin" layadmin-event="reset">
                            <i class="layui-icon layui-icon-refresh layuiadmin-button-btn"></i>
                        </button>
                        <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="table-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                <table id="{{web_table_name}}-manage" lay-filter="{{web_table_name}}-manage"></table>
            </div>
        </div>
    </div>
    <script src="../../layuiAdmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '../../layuiAdmin/', //静态资源所在路径
            version: top.layui.setter.version
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'table', 'util'], function () {
            var $ = layui.$,
                form = layui.form,
                table = layui.table,
                util = layui.util,
                admin = layui.admin;
            window.areaName = "{{web_table_name}}-manage";
          //监听搜索
          form.on('submit(table-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload(areaName, {
              where: { queryJson: JSON.stringify(field) },
              page: {
                curr: 1
              }
            });
          });
           //列表
          table.render({
              elem: '#' + areaName,
              toolbar: $.getButtons(),
              defaultToolbar: [],
              url: '/api/{{model_name}}/Get{{model_name}}PageList',
              cols: [
                [
                  { field: 'number', title: '序号', width: 100, align: 'center', type: 'numbers' },{{ for item in columns }}
                  { field: '{{item.columnname}}', title: '{{item.columndesc}}', minWidth: 100, align: 'center' },{{ end }}
                ]
              ],
              page: true,
              limit: 30,
              height: 'full-110',
              text: '对不起，加载出现异常！'
           });
          $.TableSet(table, areaName);
          var selectRow = null;
          table.on('row(' + areaName + ')', function (obj) {
            selectRow = obj.data;
            obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
          });

          var edit = function (id) {
            $.OpenTab({
              type: 2,
              title: '编辑',
              content: '{{l_model_name | string.downcase}}form.html?id=' + id,
              maxmin: true,
              area: ['700px', '470px'],
              btn: ['确定', '取消'],
              success: () => $(':focus').blur(),
              yes: function (index, layero) {
                var that = this.yes.arguments[1];
                that.find('a.layui-layer-btn0').css("pointer-events", "none");
                setTimeout(() => {
                  that.find('a.layui-layer-btn0').css("pointer-events", "")
                }, 2000)
                layero.find('iframe').contents().find('#form-submit').trigger('click');
              }
            });
          }

        var del = function (type) {
            let ids = [];
            if (type == 1 || type == undefined) {
                if (selectRow == null) return layer.msg('请选择数据');
                ids = [selectRow.cId];
            } else if (type == 2) {
                var checkData = table.checkStatus(areaName).data; //得到选中的数据
                if (checkData.length === 0) return layer.msg('请选择数据');
                ids = checkData.map(t => t.cId);
            } else {
                return layer.msg('请选择删除类型');
            }
            layer.confirm('确定删除吗？', function (index) {
              admin.req({
                type: 'post',
                url: '/api/{{model_name}}/Del{{model_name}}',
                data: { ids: ids.join(','), },
                success: function (data) {
                  if(data.code == 200) {
                    table.reload(areaName);
                    layer.close(index);
                    layer.msg('已删除!', { icon: 1, time: 1000 });
                  } else {
                    layer.close(index);
                    layer.msg(data.msg, { icon: 2, time: 1000 });
                  }
                }
              });
            });
         }

        //事件
        util.event('lay-active', {
            'x-add': () => edit(),
            'x-delete': () => del(),
            'x-batch-delete': () => del(2),
            'x-edit': () => edit(selectRow.cId)
        });
    });
    </script>
</body>

</html>